﻿package mortal.game.scene3D.util
{
    import Message.Public.*;
    import baseEngine.system.*;
    import com.gengine.debug.*;
    import com.gengine.utils.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import flash.utils.*;
    import frEngine.event.*;
    import mortal.game.*;
    import mortal.game.scene3D.events.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.player.entity.*;

    public class JumpUtil extends Object
    {
        public static var minJumpTime:Number = 0.5;

        public function JumpUtil()
        {
            return;
        }// end function

        public static function jumpPoints(param1:MovePlayer, param2:Array) : void
        {
            var jumpNext:Function;
            var player:* = param1;
            var ary:* = param2;
            jumpNext = function () : void
            {
                var _loc_1:* = ary.shift();
                if (_loc_1)
                {
                    FrEventDispatcher.instance.proxyDispatchEvent(player, PlayerEvent.JumpPointStart, [player]);
                    jump(player, _loc_1.x, _loc_1.y, jumpNext);
                }
                else
                {
                    FrEventDispatcher.instance.proxyDispatchEvent(player, PlayerEvent.JumpPointEnd, [player]);
                }
                return;
            }// end function
            ;
            Global3D.stageFrame = 60;
            ary.shift();
            JumpUtil.jumpNext();
            return;
        }// end function

        public static function jump(param1:MovePlayer, param2:int, param3:int, param4:Function = null) : void
        {
            var tm:TweenMax;
            var player:* = param1;
            var toX:* = param2;
            var toY:* = param3;
            var jumpCallBack:* = param4;
            player.stopMove();
            Global3D.stageFrame = 60;
            player.updateMount(0);
            player.setAction(ActionType.Jump, ActionName.Jump);
            player.bodyPlayer.gotoFrame(0);
            player.setRealPoint(toX, toY);
            player.direction = MathUitl.getAngleByXY(player.x2d, player.y2d, toX, toY);
            if (TweenMax.isTweening(player))
            {
                return;
            }
            tm = TweenMax.to(player, 1.1, {x2d:toX, y2d:toY, frameInterval:1, ease:Linear.easeIn, onUpdate:function () : void
            {
                var _loc_1:* = undefined;
                player.checkArea();
                if (player is RolePlayer)
                {
                    (player as RolePlayer).setCurrentPointImpl();
                    ThingUtil.isMoveChange = true;
                    _loc_1 = 1 - 0.2 * Math.sqrt(1 - (tm.currentProgress - 0.5) * (tm.currentProgress - 0.5) / 0.25);
                    Game.scene.sceneScale = _loc_1;
                    RolePlayer.instance.scaleX = 1 / _loc_1;
                    RolePlayer.instance.scaleY = 1 / _loc_1;
                    RolePlayer.instance.scaleZ = 1 / _loc_1;
                }
                else
                {
                    ThingUtil.isEntitySort = true;
                }
                return;
            }// end function
            , onComplete:function () : void
            {
                player.updateCurrentAlpha();
                player.removeTweenLite();
                if (player.entityInfo)
                {
                    player.updateMount(player.entityInfo.entityInfo.mountCode);
                }
                if (jumpCallBack != null)
                {
                    jumpCallBack.call();
                }
                return;
            }// end function
            });
            player.tweenLite = tm;
            return;
        }// end function

        public static function somersault(param1:MovePlayer, param2:int, param3:int, param4:Function = null) : void
        {
            var tween:Function;
            var player:* = param1;
            var toX:* = param2;
            var toY:* = param3;
            var jumpCallBack:* = param4;
            tween = function () : void
            {
                player.tweenLite = TweenMax.to(player, 0.625, {x2d:toX, y2d:toY, frameInterval:1, ease:Linear.easeIn, onUpdate:function () : void
                {
                    player.checkArea();
                    if (player is RolePlayer)
                    {
                        (player as RolePlayer).setCurrentPointImpl();
                        ThingUtil.isMoveChange = true;
                    }
                    else
                    {
                        ThingUtil.isEntitySort = true;
                    }
                    return;
                }// end function
                , onComplete:function () : void
                {
                    player.updateCurrentAlpha();
                    player.removeTweenLite();
                    if (jumpCallBack != null)
                    {
                        jumpCallBack.call();
                    }
                    FrEventDispatcher.instance.proxyDispatchEvent(player, PlayerEvent.JumpPointEnd, [player]);
                    return;
                }// end function
                });
                return;
            }// end function
            ;
            if (!player)
            {
                return;
            }
            Log.debug("翻滚开始时间", getTimer());
            player.stopMove();
            player.setRealPoint(toX, toY);
            player.setAction(ActionType.Jump, ActionName.Somersault);
            player.direction = MathUitl.getAngleByXY(player.x2d, player.y2d, toX, toY);
            if (TweenMax.isTweening(player))
            {
                return;
            }
            setTimeout(tween, 0.1);
            Global3D.stageFrame = 60;
            return;
        }// end function

        public static function jumpCut(param1:MovePlayer, param2:int, param3:int, param4:Number = 0.7, param5:Number = 1, param6:Function = null) : void
        {
            var player:* = param1;
            var toX:* = param2;
            var toY:* = param3;
            var time:* = param4;
            var totalTime:* = param5;
            var jumpCallBack:* = param6;
            player.stopMove();
            player.direction = MathUitl.getAngleByXY(player.x2d, player.y2d, toX, toY);
            player.setRealPoint(toX, toY);
            if (TweenMax.isTweening(player))
            {
                return;
            }
            Global3D.stageFrame = 60;
            player.tweenLite = TweenMax.to(player, time, {x2d:toX, y2d:toY, frameInterval:1, ease:Linear.easeIn, onUpdate:function () : void
            {
                player.checkArea();
                if (player is RolePlayer)
                {
                    (player as RolePlayer).setCurrentPointImpl();
                    ThingUtil.isMoveChange = true;
                }
                else
                {
                    ThingUtil.isEntitySort = true;
                }
                return;
            }// end function
            , onComplete:function () : void
            {
                player.updateCurrentAlpha();
                player.removeTweenLite();
                return;
            }// end function
            });
            setTimeout(function () : void
            {
                FrEventDispatcher.instance.proxyDispatchEvent(player, PlayerEvent.SkillPointEnd, [player]);
                return;
            }// end function
            , totalTime * 1000);
            return;
        }// end function

    }
}
